package com.hzx.consumer;

import com.hzx.OrderTable;
import com.hzx.mapper.ActivityMapper;
import com.hzx.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class KafkaConsumer {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    ActivityMapper activityMapper;

    @KafkaListener(topics = "orderTopic", groupId = "order-com.com.hzx.consumer")
    @Transactional
    public void onMessage(OrderTable orderTable) {
        activityMapper.deleteActivity(orderTable.getAId());
        orderMapper.insert(orderTable);
    }
}
